﻿using UnityEngine;
using System.Collections;

public class InputController : Singleton<InputController> {
	//vars
	private bool _rightButtonDown 			= false;
	private bool _leftButtonDown 			= false;
	private bool _middleButtonDown 			= false;
	private Vector3 _mousePosition	 		= Vector3.zero;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		if (!_rightButtonDown && Input.GetMouseButtonDown (1)) {
			_rightButtonDown 		= true;
			_mousePosition 			= Input.mousePosition;
		}

		if (Input.GetMouseButtonUp(1)) {
			_rightButtonDown = false;
		}

		if (!_middleButtonDown && Input.GetMouseButtonDown (2)) {
			_middleButtonDown 		= true;
			_mousePosition 			= Input.mousePosition;
		}
		
		if (Input.GetMouseButtonUp(2)) {
			_middleButtonDown = false;
		}

		if (_rightButtonDown) {
			CameraController.Instance.Rotate(_mousePosition.x -  Input.mousePosition.x);
			_mousePosition 			= Input.mousePosition;
		}
		if (_middleButtonDown) {
			CameraController.Instance.Pan(new Vector3(-(_mousePosition.x -  Input.mousePosition.x), 0, -(_mousePosition.y -  Input.mousePosition.y)) / 50);
			_mousePosition 			= Input.mousePosition;
		}
		if (Input.GetAxis("Mouse ScrollWheel") != 0) {
			CameraController.Instance.Zoom (Input.GetAxis("Mouse ScrollWheel"));
		}
	}
}
